-- cure
-- create by panyl
-- 技能: 恢复目标总生命值，根据威力和魔力计算


return {
    apply = function(source, target, skillId, round, para, extra)
        -- 1. 威力
        local force = para[1];

        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, true);

        --最终威力
        local force = math.modf(force * (addon_rate + 1000)/1000);

        -- 2. 施展方的魔力
        local magic = source:getMagic();

        -- 3. 作用
        local hp = math.modf(force * (magic + 3) / 1000);

        -- 概率双倍
        local prop = PropM.combine(source, "skill_double", skillId);
        if prop[3] > 0 then
            hp = hp + PropM.trigger(source, prop[1], prop[2], hp);
        end

        -- 牧师天赋额外增加max_hp属性
        prop = PropM.combine(source, "skill_additional", skillId);
        PropM.trigger(source, prop[1], prop[2]);

        -- 附带清楚状态效果
        prop = PropM.combine(source, "cure_clear", skillId);
        if prop[3] > 0 then
            PropM.trigger(source, prop[1], prop[2], target);
        end

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        CombatM.receiveCure(source, target, hp);

        EventMgr.fire(event.HP_RECOVER, hp);

        -- 作用目标
        return { target, };
    end,

    check = function(skillId, para)
        local dbase = SkillM.query(skillId, "dbase");
        if type(dbase) == "table" then
            if dbase["clean_debuff"] == 1 then
                -- 是类似于痊愈术的技能
                return true;
            end

            if dbase["clean_debuff"] == 2 then
                -- 神恩术有天赋时可用
                local prop = PropM.combine(ME.user, "all_clear", skillId);
                if PropM.apply(prop, 1) > 0 then
                    return true;
                end
            end
        end

        local ret = DungeonM.canRecoverAttrib(ME.user, "hp");
        return ret;
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 1. 威力
        local base = para[1];

        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, false);

        --最终威力
        local force = math.modf(base * (addon_rate + 1000)/1000);

        -- 2. 施展方的魔力
        local magic = source:getMagic();

        -- 3. 作用/计算时魔力+3
        local hpBase = math.modf(base * (magic + 3) / 1000);
        local hpForce = math.modf(force * (magic + 3) / 1000);
        local hpAddon = hpForce - hpBase;
        -- 牧师天赋额外增加hp属性,增加最大HP，这里不计算
        if hpAddon == 0 then
            desc = string.gsub(desc, "{cure}", hpForce);
        else
            desc = string.gsub(desc, "{cure}", hpBase .. "(+" .. hpAddon .. ")");
        end

        return desc;
    end,
}
